package com.mht.student.rest;



import com.mht.student.entity.Student;
import com.mht.student.service.StudentManageService;
import com.mht.student.service.SudentScoreService;

import java.util.List;
import java.util.Scanner;

@SuppressWarnings("all")
public class StudentManageController {
    public static void main(String[] args) {
        StudentManageService manager = new StudentManageService();
        SudentScoreService score = new SudentScoreService();
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("==========学生成绩管理系统菜单==========");
            System.out.println("1. 添加学生信息");
            System.out.println("2. 删除学生信息");
            System.out.println("3. 修改学生信息");
            System.out.println("4. 根据关键字查询学生");
            System.out.println("5. 查询所有的学生信息");
            System.out.println("6. 根据单科成绩排序");
            System.out.println("7. 根据总成绩排序");
            System.out.println("8. 根据平均成绩排序");
            System.out.println("9. 查询每个课程的最高分、最低分、平均成绩");
            System.out.println("10. 查询每个班级某门课程的优秀率和不及格率");
            System.out.println("0. 退出系统");
            System.out.print("请选择操作(0-10): ");

            int choice = scanner.nextInt();
            scanner.nextLine();  // 读取换行符

            switch (choice) {
                case 1:
                    System.out.print("输入学号: ");
                    String id = scanner.nextLine();
                    System.out.print("输入姓名: ");
                    String name = scanner.nextLine();
                    System.out.print("输入班级: ");
                    String className = scanner.nextLine();
                    System.out.print("输入Java成绩: ");
                    int chineseScore = scanner.nextInt();
                    System.out.print("输入数学成绩: ");
                    int mathScore = scanner.nextInt();
                    System.out.print("输入英语成绩: ");
                    int englishScore = scanner.nextInt();
                    scanner.nextLine();  // 读取换行符
                    manager.addStudent(new Student(id, name, className, chineseScore, mathScore, englishScore));
                    break;
                case 2:
                    System.out.print("输入要删除的学生学号: ");
                    String deleteId = scanner.nextLine();
                    manager.deleteStudent(deleteId);
                    break;
                case 3:
                    System.out.print("输入要修改的学生学号: ");
                    String updateId = scanner.nextLine();
                    System.out.print("输入新的姓名: ");
                    String newName = scanner.nextLine();
                    System.out.print("输入新的班级: ");
                    String newClassName = scanner.nextLine();
                    System.out.print("输入新的Java成绩: ");
                    int newChineseScore = scanner.nextInt();
                    System.out.print("输入新的数学成绩: ");
                    int newMathScore = scanner.nextInt();
                    System.out.print("输入新的英语成绩: ");
                    int newEnglishScore = scanner.nextInt();
                    scanner.nextLine();  // 读取换行符
                    manager.updateStudent(new Student(updateId, newName, newClassName, newChineseScore, newMathScore, newEnglishScore));
                    break;
                case 4:
                    System.out.print("输入关键字(姓名、学号或班级): ");
                    String keyword = scanner.nextLine();
                    List<Student> searchResults = manager.getStudentList(keyword);
                    System.out.println("查询结果:");
                    for (Student student : searchResults) {
                        System.out.println(student.toPrint());
                    }
                    break;
                case 5:
                    List<Student> studentList = manager.getStudentList("");
                    System.out.println("查询结果:");
                    for (Student student : studentList) {
                        System.out.println(student.toPrint());
                    }
                    break;
                case 6:
                    System.out.print("输入科目名称(Java、数学或英语): ");
                    String subject = scanner.nextLine();
                    List<Student> sortedBySubject = score.sortStudentsBySubject(subject);
                    System.out.println("按" + subject + "成绩排序:");
                    for (Student student : sortedBySubject) {
                        System.out.println(student.toPrint());
                    }
                    break;
                case 7:
                    List<Student> sortedByTotalScore = score.sortStudentsByTotalScore();
                    System.out.println("按总成绩排序:");
                    for (Student student : sortedByTotalScore) {
                        System.out.println(student.toPrint());
                    }
                    break;
                case 8:
                    List<Student> sortedByAverageScore = score.sortStudentsByAverageScore();
                    System.out.println("按平均成绩排序:");
                    for (Student student : sortedByAverageScore) {
                        System.out.println(student.toPrint());
                    }
                    break;
                case 9:
                    System.out.print("输入科目名称(Java、数学或英语): ");
                    String course = scanner.nextLine();
                    score.printCourseStatistics(course);
                    break;
                case 10:
                    System.out.print("输入班级名称: ");
                    String classForRate = scanner.nextLine();
                    System.out.print("输入科目名称(Java、数学或英语): ");
                    String courseForRate = scanner.nextLine();
                    score.printClassCourseRates(classForRate, courseForRate);
                    break;
                case 0:
                    System.out.println("退出系统");
                    scanner.close();
                    System.exit(0);
                default:
                    System.out.println("无效的选择，请重新输入");
            }
        }
    }
}
